<?php 
include('./fun.php');
$conn=my_sql($cfg);
$re=adm_login();
if($re['err']=='no_login'){die('<script>no_login()</script>');}
if($re['err']!='ok'){die('<hh><b>'.$re['err'].'</b></hh>');}
$adm=$re['adm'];

$set=get_set(1);

if($adm['power']!='adm'){no_power();}


?>
<style>
ll{float:left;width:100%;}
.logo{float:left;width:50px;height:50px;border-radius:50%}
l{margin-top:10px;padding-left:180px}
view{float:left;width:120px;padding:5px}
view div{float:left;width:100%;background:#efefef;border-radius:5px;height:80px;line-height:80px;text-align:center;color:#999;font-size:50px !important;}
anyou{float:left;width:100%;font-size:16px;height:32px;line-height:24px;margin-top:5px;padding-top:4px;padding-left:5px;padding-right:5px}
anyou a{float:right;height:24px;line-height:24px;margin-left:5px;padding-left:10px;padding-right:10px;font-size:13px}
anyou:hover{background:#efefef}
view icon{position:absolute;color:crimson;line-height:20px;right:10px;top:10px}
.img{float:left;width:40px;}
.bg{float:left;width:80px;}
save_bt{position:fixed;width:100%;z-index:10000;bottom:-100px;left:0;display:flex;justify-content:center;}
save_bt a{float:left;width:160px;height:45px;line-height:45px;background:crimson;color:#fff;text-align:center;}
.save_show{bottom:10px}
</style>
<save_bt class="m" >
<a onclick="save($(this))">保存更改</a>
</save_bt>
<hh><b>系统设置</b></hh>
<help style="margin-top:0">本页面修改信息，将可能会对应用产生错误，请修改前认真确认信息，修改后请测试。</help>
<mm>






<ll style="width:50%;padding:10px">
<box><b>系统设置</b>

<l><text>站点名称</text>
<input placeholder="站点名称" value="<?php echo $set['webname']?>" c="webname" onchange="val_change($(this))">
</l>



<l><text>图标</text>
<img class="logo" src="<?php echo ($set['logo']?$set['logo']:$cfg['no_img']) ?>" onclick="right({title:'选择图标',url:'select_img.php?action=select_logo($(this))',width:'75vw'})">
</l>

<l><text>地图mapkey</text>
<input placeholder="地图mapkey" value="<?php echo $set['mapkey']?>" c="mapkey" onchange="val_change($(this))">
<h>腾讯地图的mapkey,用于小程序导航位置</h>
</l>




<l id="bg"><text>网站登录背景</text>
<bgs>
<?php 
if($set['bg']){

foreach($set['bg'] as $v){
echo '<view>
<div style="background:url('.$v.') no-repeat center;background-size:cover;" img="'.$v.'">
<icon class="icon icon-del1" onclick="bg_del($(this))" c="bg"></icon>
</div>    
</view>';
}
}

?>
</bgs>
<view >
<div class="icon icon-plus" onclick="right({title:'选择背景图',url:'select_img.php?action=select_bg($(this))',width:'75vw'})"></div>
</view>

</l>

</box>

<box style="margin-top:20px">
<b>支付设置</b>
<l><text>商户号</text>
<input placeholder="微信支付平台商户号" value="<?php echo $set['mch_id']?>" c="mch_id" onchange="val_change($(this))">
</l>

<l><text>支付密匙</text>
<input placeholder="支付密匙" value="<?php echo '***'.substr($set['pay_key'],5,10).'***';?>" c="pay_key" onchange="val_change($(this))">
</l>

<b>支付密匙</b>

<l ><text>证书名称</text>
<input placeholder="证书名称" value="<?php echo $set['pem_name']?>" c="pem_name" onchange="val_change($(this))">

</l>

<l style="height:auto"><text>私匙</text>
<textarea placeholder="key_pem" c="key_pem" onchange="val_change($(this))" style="float:left;width:100%;height:80px;">
<?php echo '***'.substr($set['key_pem'],5,10).'***';?>
</textarea>
</l>

<l style="height:auto"><text>公匙</text>
<textarea placeholder="cert_pem" c="cert_pem" onchange="val_change($(this))" style="float:left;width:100%;height:80px;">
<?php echo '***'.substr($set['cert_pem'],5,10).'***';?>
</textarea>
</l>

<b>账户结算</b>

<l><text>是否开启分账</text>
<switch class="<?php echo ($set['profit_sharing']?'switch_true':'')?>" onclick="switch_it($(this))" c="profit_sharing"><x></x></switch>
<h style="float:left;width:100%;">佣金支出，请设置分账模式打开，请开启分账。</h>
</l>


<l><text>退款时效(小时)</text>
<input placeholder="急速退款时效" value="<?php echo $set['tui_time']?>" c="tui_time" onchange="val_change($(this))" type="number">
</l>

<l ><text>团长邀请时效</text>
<input placeholder="团长邀请时效" value="<?php echo $set['cps_time']?>" c="cps_time" onchange="val_change($(this))" type="number">
</l>

<b>积分设置</b>
<l><text>购物获得积分</text>
<input placeholder="购物时每1元获得的积分 >0时候开启" value="<?php echo $set['pay_jifen']?>" c="pay_jifen" onchange="val_change($(this))" type="number">
</l>

<l><text>购物使用积分</text>
<input placeholder="购物时使用的积分 每1元兑换的积分" value="<?php echo $set['buy_jifen']?>" c="buy_jifen" onchange="val_change($(this))" type="number">
</l>

<l><text>最小积分额</text>
<input placeholder="购物时候，最少使用的积分数" value="<?php echo $set['buy_jifen_min']?>" c="buy_jifen_min" onchange="val_change($(this))" type="number">
</l>
<l><text>分享积分</text>
<input placeholder="分享邀新积分" value="<?php echo $set['share_jifen']?>" c="share_jifen" onchange="val_change($(this))" type="number">
</l>

</box>


</ll>

<ll style="width:50%;padding:10px">
<box><b>小程序设置</b>
<l><text>小程序名称</text>
<input placeholder="小程序标题" value="<?php echo $set['app_title']?>" c="app_title" onchange="val_change($(this))">
</l>


<l><text>小程序说明</text>
<input placeholder="小程序说明" value="<?php echo $set['info']?>" c="info" onchange="val_change($(this))">
</l>

<l><text>关注二维码</text>
<img class="logo" style="border-radius:0" src="<?php echo ($set['qr']?$set['qr']:$cfg['no_img']) ?>" onclick="right({title:'选择关注二维码',url:'select_img.php?action=select_qr($(this))',width:'75vw'})">
</l>


<l><text>关注说明</text>
<input placeholder="首页关注说明" value="<?php echo $set['qr_info']?>" c="qr_info" onchange="val_change($(this))">
</l>

<l id="login_bg"><text>登录背景</text>
<bgs>
<?php 
if($set['login_bg']){

foreach($set['login_bg'] as $v){
echo '<view>
<div style="background:url('.$v.') no-repeat center;background-size:cover;" img="'.$v.'">
<icon class="icon icon-del1" onclick="bg_del($(this))" c="login_bg"></icon>
</div>    
</view>';
}
}

?>
</bgs>
<view >
<div class="icon icon-plus" onclick="right({title:'选择背景图',url:'select_img.php?action=select_login_bg($(this))',width:'75vw'})"></div>
</view>

</l>


<l id="app_bg"><text>应用默认背景</text>
<bgs>
<?php 
if($set['app_bg']){

foreach($set['app_bg'] as $v){
echo '<view>
<div style="background:url('.$v.') no-repeat center;background-size:cover;" img="'.$v.'">
<icon class="icon icon-del1" onclick="bg_del($(this))" c="app_bg"></icon>
</div>    
</view>';
}
}

?>
</bgs>
<view >
<div class="icon icon-plus" onclick="right({title:'选择背景图',url:'select_img.php?action=select_app_bg($(this))',width:'75vw'})"></div>
</view>

</l>


<l><text>是否开启新人跳转</text>
<switch class="<?php echo ($set['go_to_new']?'switch_true':'')?>" onclick="switch_it($(this))" c="go_to_new"><x></x></switch>
<h style="float:left;width:100%;">新用户注册后，跳转到修改信息页面。</h>
</l>




<l><text>员工邀请标题</text>
<input placeholder="员工邀请标题" value="<?php echo $set['emp_title']?>" c="emp_title" onchange="val_change($(this))">
</l>

<l><text>员工邀请分享图</text>
<img class="bg" style="border-radius:0" src="<?php echo ($set['emp_bg']?$set['emp_bg']:$cfg['no_img']) ?>" onclick="right({title:'选择关注二维码',url:'select_img.php?action=select_emp_bg($(this))',width:'75vw'})">
</l>

<l><text>团长邀请标题</text>
<input placeholder="团长邀请标题" value="<?php echo $set['tz_title']?>" c="tz_title" onchange="val_change($(this))">
</l>
<l><text>团长邀请分享图</text>
<img class="bg" style="border-radius:0" src="<?php echo ($set['tz_bg']?$set['tz_bg']:$cfg['no_img']) ?>" onclick="right({title:'选择关注二维码',url:'select_img.php?action=select_tz_bg($(this))',width:'75vw'})">
</l>

<l><text>首页获取位置</text>
<switch class="<?php echo ($set['get_pos']?'switch_true':'')?>" onclick="switch_it($(this))" c="get_pos"><x></x></switch>
<h style="float:left;width:100%;">首页获取位置，如果不开启，可以获取更好的速度。</h>
</l>


<l><text>首页登录</text>
<switch class="<?php echo ($set['index_login']?'switch_true':'')?>" onclick="switch_it($(this))" c="index_login"><x></x></switch>
<h style="float:left;width:100%;">首页打开就进行登录，默认开启。</h>
</l>

<l><text>默认门店ID</text>
<input placeholder="默认的门店ID" value="<?php echo $set['shop_id']?>" c="shop_id" onchange="val_change($(this))">
</l>


</box>




</ll>



</mm>






<script>
$(document).ready(function(){
window.save_data={}
});



function val_change(o){
var c=o.attr('c');if(!c){msg('参数错误');return;}
var val=o.val();
window.save_data[[c]]=val;
save_show();
}

function save_show(ac){
if(ac){$('save_bt').removeClass('save_show');}else{
$('save_bt').addClass('save_show');
}
}
function save(){if(!window.save_data){msg('请输入需要保存的数据');return;}
if(!confirm("是否需要保存更改?")){return;}
post('set_change',window.save_data,1,function(res){
msg('修改成功');save_show(1);
main_load();
});
}



function switch_this(o){
var c=o.attr('c');if(!c){msg('参数错误');return;}var val=1;
if(o.hasClass('switch_select')){val=0;}
if(val==0){o.removeClass('switch_select')}else{
o.addClass('switch_select')
}

window.save_data[[c]]=val;
save_show();
return;
post('set_change',{[c]:val},1,function(res){
if(val==0){o.removeClass('switch_select')}else{
o.addClass('switch_select')
}
});

}

function anyou_edit(o){
var id=o.attr('i');if(!id){id=0;}
right({title:'案由参数编辑',url:'adm/anyou_edit.php?id='+id,width:'400px'})

}

function anyou_del(o){
var id=o.attr('i');if(!id){msg('请指定需要删除的案由');return;}
if(!confirm("是否删除案由?")){return;}
post('data_del','',id,function(res){
    msg('删除成功');
    main_load();
});
}

function select_logo(o){
var img=o.attr('img_480');
post('set_change',{'logo':img},1,function(res){
main_load();
right_close();
msg('修改logo成功');
});
}

function select_qr(o){
var img=o.attr('img_480');
post('set_change',{'qr':img},1,function(res){
main_load();
right_close();
msg('修改关注二维码成功');
});
}

function select_emp_bg(o){
var img=o.attr('img_750');
post('set_change',{'emp_bg':img},1,function(res){
main_load();
right_close();

});
}
function select_tz_bg(o){
var img=o.attr('img_750');
post('set_change',{'tz_bg':img},1,function(res){
main_load();
right_close();

});
}


function select_jc_marker(o){
var img=o.attr('img_240');
post('set_change',{'jc_marker':img},1,function(res){
main_load();
right_close();
msg('修改图标成功');
});
}

function select_msg_marker(o){
var img=o.attr('img_240');
post('set_change',{'msg_marker':img},1,function(res){
main_load();
right_close();
msg('修改图标成功');
});
}

function select_bg(o){
var img=o.attr('img_1080');
post('set_bg',{'img':img,c:'bg'},1,function(res){
main_load();
msg('登录背景添加成功');
});
}


function select_login_bg(o){
var img=o.attr('img_1080');
post('set_bg',{'img':img,c:'login_bg'},1,function(res){
main_load();
msg('登录背景添加成功');
});
}


function select_app_bg(o){
var img=o.attr('img_750');
post('set_bg',{'img':img,c:'app_bg'},1,function(res){
main_load();
msg('登录背景添加成功');
});
}

function bg_del(o){
var c=o.attr('c');if(!c){c='bg';}
o.parent().parent().remove();
bg_save(c);
}

function bg_save(cc){
var data=[];
$('#'+cc+' div').each(function(){
var img=$(this).attr('img');
if(img){
data.push(img);
}
});
console.log(data);


post('set_change',{[cc]:data},1,function(res){
main_load();

msg('删除成功');
});

}

function switch_it(o){
var c=o.attr('c');var val='stop';
if(!o.hasClass('switch_true')){
val=1;
}
if(val!=1){o.removeClass('switch_true')}else{
o.addClass('switch_true')
}
window.save_data[[c]]=val;
save_show();
return;
post('set_change',{[c]:val},1,function(res){
msg('修改成功');    
main_load();});
}



</script>